<?php
/*
 * 管理员操作
 */
include_once '../common_mbs.inc.php';
include_once '../smarty.inc.php';

//判断访问权限
$admin_index_module_obj = new osgh_admin_index_module_cls();
$is_warrant = $admin_index_module_obj->is_have_warrant($_ADMIN_ID,'admin_index_main');
if(!$is_warrant) tcmc_cls::ShowMsg("没有权限访问！", "../index_body.html");

$action          = trim($_GET['action']);
$admin_index_obj = new osgh_admin_index_tbl_cls();
 
$admin_name =  trim($_REQUEST['admin_name']);
$real_name  =  trim($_REQUEST['real_name']);
$password   =  trim($_REQUEST['password']);
$group_id   = trim($_POST['group_id']);
$admin_id   =  intval($_REQUEST['admin_id']);
$district   =  intval($_REQUEST['district']);
if ($action == "add")
{	
	if ($admin_index_obj->getAdminIndexList(TRUE, "admin_name='{$admin_name}'"))
	{
		tcmc_cls::ShowMsg("已存在该用户！", "admin_index_main.php");
	}
	$add_array = array(
		'admin_name'   => $admin_name,
		'password'     => md5($password),
		'real_name'    => $real_name,
		'group_id'     => $group_id,
		'district'     => $district,
		'is_available' => 1		
		);
	$uid = $admin_index_obj->addAdminIndex($add_array);

	$log_data = array(
		'user_id' => $_ADMIN_ID,
		'module_code' => $g_osgh_module,
		'remark' => "添加管理员，管理员编号 {$uid} ",
		'ip' => $_client_ip,
		'add_time' => time()
	);
	osgh_admin_log_tbl_cls::add($log_data);

	tcmc_cls::ShowMsg("添加管理员成功！", "admin_index_main.php");
}
else if( $action == 'edit' )
{   
     $up_data = array(
	 'admin_name' => $admin_name,
	 'real_name' =>$real_name,	
	 'district'     => $district,	 
	 'group_id'   => $group_id  
	 );	     
    if(!empty($password))
    {
	$pwd = md5($password);
	$up_data = array(
	 'admin_name' => $admin_name,
	 'password'   => $pwd,    
	 'district'     => $district,
	 'real_name'  =>$real_name,	
	 'group_id'   => $group_id   
	 );	
    }
    $up_str  = "admin_id={$admin_id}";
    $up_result = $admin_index_obj->updateAdminIndex($up_data, $up_str);
    $log_data = array(
		'user_id' => $_ADMIN_ID,
		'module_code' => $g_osgh_module,
		'remark' => "修改管理员，管理员编号 {$admin_id} ",
		'ip' => $_client_ip,
		'add_time' => time()
	);
	osgh_admin_log_tbl_cls::add($log_data);
    tcmc_cls::ShowMsg("修改管理员成功！", "admin_index_main.php");
}
else if ($action == 'upgrade')
{
	$admin_id = intval($_REQUEST['aid']);

	$up_data = array(
		'is_available' => 1,	
	);
	$up_str  = "admin_id={$admin_id}";
	$up_result = $admin_index_obj->updateAdminIndex($up_data, $up_str);

	if ($up_result)
	{
		$log_data = array(
			'user_id' => $_ADMIN_ID,
			'module_code' => $g_osgh_module,
			'remark' => "启用管理员成功，管理员编号 {$admin_id} ",
			'ip' => $_client_ip,
			'add_time' => time()
		);
		osgh_admin_log_tbl_cls::add($log_data);

		tcmc_cls::ShowMsg("启用管理员成功！", "admin_index_main.php");
	}
	else 
	{
		tcmc_cls::ShowMsg("启用管理员失败！", "admin_index_main.php");
	}
}
else if ($action == "delprivi")
{		
	$osgh_admin_id_module_obj  = new osgh_admin_id_module_tbl_cls();
	$admin_id = intval($_REQUEST['aid']);

	$admin_index_obj->delAdminIndex($admin_id);
	$osgh_admin_id_module_obj->delAdminModule(0, $admin_id);
	echo 
	$log_data = array(
		'user_id' => $_ADMIN_ID,
		'module_code' => $g_osgh_module,
		'remark' => "禁用管理员，管理员编号 {$admin_id} ",
		'ip' => $_client_ip,
		'add_time' => time()
	);
	osgh_admin_log_tbl_cls::add($log_data);
	tcmc_cls::ShowMsg("禁用管理员成功！", "admin_index_main.php");
}
else if ($_GET['action'] == "save_warrant")
{	
    $admin_id =  $_GET['aid'];
    $str='';
    $admin_id_module_obj = new osgh_admin_id_module_tbl_cls();
    $admin_id_module_obj->delAdminModule(0, $admin_id);
    $warrant = count($_POST['module_no_c']);
    if(!empty($warrant))
    {
        for($i=0;$i<$warrant;$i++)
        {
            $str .='("'.$admin_id.'","'.$_POST['module_no_c'][$i].'"),';
        }
        $str = substr($str,0,-1);
        $admin_id_module_obj->queryAdminModule($str);
    }
    $log_data = array(
		'user_id' => $_ADMIN_ID,
		'module_code' => $g_osgh_module,
		'remark' => "修改管理员权限组，管理员编号 {$admin_id} ",
		'ip' => $_client_ip,
		'add_time' => time()
    );
    osgh_admin_log_tbl_cls::add($log_data);
    tcmc_cls::ShowMsg("权限组修改成功！", "admin_index_main.php");   
}
 

?>